Total Complexity | 3 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { DynamicModule, Global, Module } from '@nestjs/common'; |
||
7 | |||
8 | @Global() |
||
9 | @Module({ |
||
10 | providers: [ |
||
11 | RbacService, |
||
12 | StorageRbacService, |
||
13 | Reflector, |
||
14 | ], |
||
15 | imports: [], |
||
16 | exports: [ |
||
17 | RbacService, |
||
18 | ], |
||
19 | }) |
||
20 | export class RBAcModule { |
||
21 | static forRoot( |
||
22 | rbac: IStorageRbac, |
||
23 | providers?: any[], |
||
24 | imports?: any[], |
||
25 | ): DynamicModule { |
||
26 | |||
27 | return RBAcModule.forDynamic( |
||
28 | /* tslint:disable */ |
||
29 | class { |
||
30 | async getRbac(): Promise<IStorageRbac> { |
||
31 | return rbac; |
||
32 | }; |
||
33 | }, |
||
34 | providers, |
||
35 | imports, |
||
36 | ); |
||
37 | } |
||
38 | |||
39 | static forDynamic( |
||
40 | rbac: new () => IDynamicStorageRbac, |
||
41 | providers?: any[], |
||
42 | imports?: any[], |
||
43 | ): DynamicModule { |
||
44 | return { |
||
45 | module: RBAcModule, |
||
46 | providers: [ |
||
47 | ...(providers || []), |
||
48 | rbac, |
||
49 | { |
||
50 | provide: StorageRbacService, |
||
51 | useFactory: (moduleRef: ModuleRef, rbacService: IDynamicStorageRbac) => { |
||
52 | return new StorageRbacService(moduleRef, rbacService); |
||
53 | }, |
||
54 | inject: [ModuleRef, rbac], |
||
55 | }, |
||
56 | ], |
||
57 | imports: [ |
||
58 | ...(imports || []), |
||
59 | ], |
||
63 |